package org.hako.recite.word.tool;

import java.util.Arrays;

/**
 * Result of kannji extract operation.
 * 
 * @since 0.4.14
 * @author <a href="mailto:xnnyygn@gmail.com">xnnyygn</a>
 */
public class KannjiExtractResult {

	private int[] indexArray;
	private int count;

	/**
	 * Create
	 */
	public KannjiExtractResult() {
		this(2);
	}

	/**
	 * Create
	 * 
	 * @param size
	 */
	public KannjiExtractResult(int size) {
		super();
		indexArray = new int[size];
		count = 0;
	}

	public void add(int index) {
		if (count == indexArray.length) {
			int[] tmpArray = new int[count * 2];
			System.arraycopy(indexArray, 0, tmpArray, 0, count);
			indexArray = tmpArray;
		}
		indexArray[count++] = index;
	}

	public int getCount() {
		return count;
	}

	public int get(int index) {
		return indexArray[index];
	}

	@Override
	public String toString() {
		return "KannjiExtractResult [indexArray=" + Arrays.toString(indexArray)
				+ ", count=" + count + "]";
	}

}
